package zjimu1.test;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView.Renderer;

public class MyRenderer implements Renderer {

	FlourOne one,two;
	FlourAll all;
	Square square;
	public MyRenderer()
	{
		one=new FlourOne(20000,10000,20000);
		two=new FlourOne(20000,10000,20000);
		//two.PutPossion(30000, 0, 0);
		all=new FlourAll();
		all.InitFlourArrary2();
		square=new Square(20000,40000,20000);
	}
	int angle=0;
	@Override
	public void onDrawFrame(GL10 gl) {
		// TODO Auto-generated method stub
		//gl.glEnable(GL10.GL_CULL_FACE);
		gl.glDisable(GL10.GL_CULL_FACE);
		gl.glShadeModel(GL10.GL_SMOOTH);
		gl.glFrontFace(GL10.GL_CCW);
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT);
		gl.glMatrixMode(GL10.GL_MODELVIEW);
		gl.glLoadIdentity();
		gl.glTranslatef(0, -0.5f, -2.0f);
		gl.glRotatef(angle++, 0, 1, 0);
		
		/*
		gl.glPushMatrix();
		one.DrawCube(gl);
		gl.glPopMatrix();
		gl.glPushMatrix();
		this.two.PutPossion2(30000, 0, 10000, gl);
		two.DrawCube(gl);
		gl.glPopMatrix();
		gl.glPushMatrix();
		this.two.PutPossion2(-30000, 0, 10000, gl);
		two.DrawCube(gl);
		gl.glPopMatrix();
		*/
		/*
		square.one2left(gl, 30);
		square.OverDraw(gl);
		square.PopMatrix(gl);
		square.one2left(gl, 60);
		square.OverDraw(gl);
		square.PopMatrix(gl);
		square.one2left(gl, 90);
		square.OverDraw(gl);
		square.PopMatrix(gl);
		*/
		square.one2right(gl, 0);
		square.OverDraw(gl);
		square.PopMatrix(gl);
		/*
		square.one2right(gl, 60);
		square.OverDraw(gl);
		square.PopMatrix(gl);
		*/
		square.one2right(gl, 90);
		square.OverDraw(gl);
		square.PopMatrix(gl);
		
		//all.DrawFlour(gl);
		//one.DrawCube(gl);
		gl.glFinish();
		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);	
	}

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) {
		// TODO Auto-generated method stub
		gl.glViewport(0, 0, width, height);
		gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glLoadIdentity();
		float ratio=(float)width/height;
		gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
	
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		// TODO Auto-generated method stub
		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		gl.glShadeModel(GL10.GL_SMOOTH);
		gl.glClearDepthf(1.0f);
		gl.glShadeModel(GL10.GL_SMOOTH);
		gl.glEnable(GL10.GL_DEPTH_TEST);
		gl.glDepthFunc(GL10.GL_LEQUAL);
		//this.two.PutPossion2(30000, 0, 0, gl);
		
	}

}
